﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.IO;
using MezmurStore2.Utility;
using System.Web.Mvc;

namespace MezmurStore2.Models
{
    public class MezmurStoreEntities: DbContext
    {
        public MezmurStoreEntities()
        {
            this.Configuration.AutoDetectChangesEnabled = true;
        }

        public DbSet<Album> Albums { get; set; }

        public DbSet<Track> Tracks { get; set; }

        public List<MezmurCategory> Categories = new List<MezmurCategory>() { MezmurCategory.Awdamet, MezmurCategory.Misgana, MezmurCategory.Niseha, MezmurCategory.Other, MezmurCategory.Serg };

        public List<Song> Songs
        {
            get
            {
                List<Song> songs = new List<Song>();
                var albums = this.Albums.Include(t => t.Tracks);
                foreach (var album in albums)
                {
                    foreach(var track in album.Tracks)
                    {
                        var song = new Song()
                        {
                            artist = track.ArtistName,
                            Id = track.Id,
                            poster = album.Poster,
                            title = track.Name,
                            mp3 = track.FilePath,
                            album = album.Title,
                            category = album.Gener
                        };
                        songs.Add(song);
                    }
                }
                return songs;
            }
        }


    }
}